package com.zonski.jbots.desktop.client.entity;

import com.zonski.jbots.engine.Entity;
import com.zonski.jbots.engine.Rectangle;
import com.zonski.jbots.desktop.client.EntityRenderer;
import com.zonski.jbots.game.JBotsConstants;

import java.awt.Graphics;
import java.awt.Color;
import java.awt.Image;

/**
 * Created by IntelliJ IDEA.
 * User: Chris Glover
 * Date: Oct 9, 2003
 * Time: 11:17:21 AM
 * To change this template use Options | File Templates.
 */
public class ChargerRenderer implements EntityRenderer
{
    private Image active;
    private Image inactive;

    public ChargerRenderer(Image active, Image inactive)
    {
        this.active = active;
        this.inactive = inactive;
    }

    public void render(Graphics g, Entity entity)
    {
        Rectangle bounds = entity.bounds;

        int cx = bounds.getCentreX();
        int cy = bounds.getCentreY();
        if(entity.getCharge() > 0)
        {
            int updates = entity.getEffectiveModeUpdates() / 3;
            int width = bounds.width * 2;
            int mod = (bounds.width * entity.getMaxCharge())/(entity.getCharge());
            for(int i=updates%mod; i<width; i+=mod)
            {
                int w = width - i;
                Color color = new Color(255, 255, 255, (255 * w)/width);
                //int adj = 127 + (128 * w)/width;
                //Color color = new Color(adj, adj, adj);
                g.setColor(color);
                g.drawOval(cx-i/2, cy-i/2, i-1, i-1);
            }
            g.drawImage(this.active, cx - active.getWidth(null)/2, cy - active.getHeight(null)/2, null);
        }else{
            g.drawImage(this.inactive, cx - inactive.getWidth(null)/2, cy - inactive.getHeight(null)/2, null);
        }
    }

    public Image getActiveImage()
    {
        return this.active;
    }
}
